//SPDX-FileCopyrightText: Copyright 2022-2024 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package org_forum_api_serv

import (
	"context"
	"time"

	"atomgit.com/openlinksaas/api-server/dao"
	"atomgit.com/openlinksaas/api-server/dao/org_dao"
	"atomgit.com/openlinksaas/api-server/dao/user_dao"
	"atomgit.com/openlinksaas/api-server/utils"
	"atomgit.com/openlinksaas/proto-gen-go.git/org_forum_api"
	"github.com/google/uuid"
	"go.mongodb.org/mongo-driver/mongo"
)

func (apiImpl *OrgForumApiImpl) CreateContent(ctx context.Context, req *org_forum_api.CreateContentRequest) (*org_forum_api.CreateContentResponse, error) {
	sessionItem, ok := dao.CacheDao.GetSession(ctx, req.SessionId)
	if !ok {
		return &org_forum_api.CreateContentResponse{
			Code:   org_forum_api.CreateContentResponse_CODE_WRONG_SESSION,
			ErrMsg: "会话不存在",
		}, nil
	}
	exist, err := org_dao.OrgInfoDao.Exist(ctx, req.OrgId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.CreateContentResponse{
			Code:   org_forum_api.CreateContentResponse_CODE_NO_ORG,
			ErrMsg: "组织不存在",
		}, nil
	}
	exist, err = org_dao.MemberDao.Exist(ctx, req.OrgId, sessionItem.UserId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.CreateContentResponse{
			Code:   org_forum_api.CreateContentResponse_CODE_NO_PERMISSION,
			ErrMsg: "没有权限",
		}, nil
	}
	forumItem, err := org_dao.ForumDao.Get(ctx, req.OrgId, req.ForumId)
	if err != nil {
		return &org_forum_api.CreateContentResponse{
			Code:   org_forum_api.CreateContentResponse_CODE_NO_FORUM,
			ErrMsg: "讨论组不存在",
		}, nil
	}
	forum := forumItem.ToOrgForumInfo(sessionItem.UserId)
	if !forum.UserPerm.ReplyThread {
		return &org_forum_api.CreateContentResponse{
			Code:   org_forum_api.CreateContentResponse_CODE_NO_PERMISSION,
			ErrMsg: "没有权限",
		}, nil
	}
	exist, err = org_dao.ForumThreadDao.Exist(ctx, req.OrgId, req.ForumId, req.ThreadId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.CreateContentResponse{
			Code:   org_forum_api.CreateContentResponse_CODE_NO_THREAD,
			ErrMsg: "讨论会话不存在",
		}, nil
	}

	contentId := uuid.NewString()
	nowTime := time.Now().UnixNano() / 1e6

	dbSess, err := dao.StartSession()
	if err != nil {
		return nil, err
	}
	defer dao.EndSession(dbSess)

	ret, err := dbSess.WithTransaction(ctx, func(sessCtx mongo.SessionContext) (interface{}, error) {
		err = org_dao.ThreadContentDao.Insert(sessCtx, &org_dao.ThreadContentInfoDbItem{
			ContentId:  contentId,
			OrgId:      req.OrgId,
			ForumId:    req.ForumId,
			ThreadId:   req.ThreadId,
			Content:    req.Content,
			UserId:     sessionItem.UserId,
			CreateTime: nowTime,
			UpdateTime: nowTime,
		})
		if err != nil {
			return nil, err
		}
		//更新会话计数
		count, err := org_dao.ThreadContentDao.CountByThread(sessCtx, req.OrgId, req.ForumId, req.ThreadId)
		if err != nil {
			return nil, err
		}
		err = org_dao.ForumThreadDao.UpdateContentCount(sessCtx, req.OrgId, req.ForumId, req.ThreadId, count)
		if err != nil {
			return nil, err
		}
		return &org_forum_api.CreateContentResponse{
			Code:      org_forum_api.CreateContentResponse_CODE_OK,
			ContentId: contentId,
		}, nil
	})
	if err != nil {
		return nil, err
	}
	return ret.(*org_forum_api.CreateContentResponse), nil
}

func (apiImpl *OrgForumApiImpl) UpdateContent(ctx context.Context, req *org_forum_api.UpdateContentRequest) (*org_forum_api.UpdateContentResponse, error) {
	sessionItem, ok := dao.CacheDao.GetSession(ctx, req.SessionId)
	if !ok {
		return &org_forum_api.UpdateContentResponse{
			Code:   org_forum_api.UpdateContentResponse_CODE_WRONG_SESSION,
			ErrMsg: "会话不存在",
		}, nil
	}
	exist, err := org_dao.OrgInfoDao.Exist(ctx, req.OrgId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.UpdateContentResponse{
			Code:   org_forum_api.UpdateContentResponse_CODE_NO_ORG,
			ErrMsg: "组织不存在",
		}, nil
	}
	exist, err = org_dao.MemberDao.Exist(ctx, req.OrgId, sessionItem.UserId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.UpdateContentResponse{
			Code:   org_forum_api.UpdateContentResponse_CODE_NO_PERMISSION,
			ErrMsg: "没有权限",
		}, nil
	}
	exist, err = org_dao.ForumDao.Exist(ctx, req.OrgId, req.ForumId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.UpdateContentResponse{
			Code:   org_forum_api.UpdateContentResponse_CODE_NO_FORUM,
			ErrMsg: "讨论组不存在",
		}, nil
	}
	exist, err = org_dao.ForumThreadDao.Exist(ctx, req.OrgId, req.ForumId, req.ThreadId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.UpdateContentResponse{
			Code:   org_forum_api.UpdateContentResponse_CODE_NO_THREAD,
			ErrMsg: "讨论会话不存在",
		}, nil
	}
	contentItem, err := org_dao.ThreadContentDao.Get(ctx, req.OrgId, req.ForumId, req.ThreadId, req.ContentId)
	if err != nil {
		return &org_forum_api.UpdateContentResponse{
			Code:   org_forum_api.UpdateContentResponse_CODE_NO_CONTENT,
			ErrMsg: "讨论内容不存在",
		}, nil
	}
	if contentItem.UserId != sessionItem.UserId {
		return &org_forum_api.UpdateContentResponse{
			Code:   org_forum_api.UpdateContentResponse_CODE_NO_PERMISSION,
			ErrMsg: "没有权限",
		}, nil
	}

	nowTime := time.Now().UnixNano() / 1e6

	dbSess, err := dao.StartSession()
	if err != nil {
		return nil, err
	}
	defer dao.EndSession(dbSess)

	ret, err := dbSess.WithTransaction(ctx, func(sessCtx mongo.SessionContext) (interface{}, error) {
		err = org_dao.ThreadContentDao.Update(sessCtx, req.OrgId, req.ForumId, req.ThreadId, req.ContentId, req.Content, nowTime)
		if err != nil {
			return nil, err
		}
		return &org_forum_api.UpdateContentResponse{
			Code: org_forum_api.UpdateContentResponse_CODE_OK,
		}, nil
	})
	if err != nil {
		return nil, err
	}
	return ret.(*org_forum_api.UpdateContentResponse), nil
}

func (apiImpl *OrgForumApiImpl) ListContent(ctx context.Context, req *org_forum_api.ListContentRequest) (*org_forum_api.ListContentResponse, error) {
	emptyList := []*org_forum_api.ThreadContentInfo{}

	sessionItem, ok := dao.CacheDao.GetSession(ctx, req.SessionId)
	if !ok {
		return &org_forum_api.ListContentResponse{
			Code:        org_forum_api.ListContentResponse_CODE_WRONG_SESSION,
			ErrMsg:      "会话不存在",
			ContentList: emptyList,
		}, nil
	}
	exist, err := org_dao.OrgInfoDao.Exist(ctx, req.OrgId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.ListContentResponse{
			Code:        org_forum_api.ListContentResponse_CODE_NO_ORG,
			ErrMsg:      "组织不存在",
			ContentList: emptyList,
		}, nil
	}
	exist, err = org_dao.MemberDao.Exist(ctx, req.OrgId, sessionItem.UserId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.ListContentResponse{
			Code:        org_forum_api.ListContentResponse_CODE_NO_PERMISSION,
			ErrMsg:      "没有权限",
			ContentList: emptyList,
		}, nil
	}
	exist, err = org_dao.ForumDao.Exist(ctx, req.OrgId, req.ForumId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.ListContentResponse{
			Code:        org_forum_api.ListContentResponse_CODE_NO_FORUM,
			ErrMsg:      "讨论组不存在",
			ContentList: emptyList,
		}, nil
	}
	threadItem, err := org_dao.ForumThreadDao.Get(ctx, req.OrgId, req.ForumId, req.ThreadId)
	if err != nil {
		return &org_forum_api.ListContentResponse{
			Code:        org_forum_api.ListContentResponse_CODE_NO_THREAD,
			ErrMsg:      "讨论会话不存在",
			ContentList: emptyList,
		}, nil
	}

	contentItemList, err := org_dao.ThreadContentDao.ListByThread(ctx, req.OrgId, req.ForumId, req.ThreadId, int64(req.Offset), int64(req.Limit))
	if err != nil {
		return nil, err
	}
	//获取用户信息
	userIdList := []string{}
	for _, contentItem := range contentItemList {
		userIdList = append(userIdList, contentItem.UserId)
	}
	userItemList, err := user_dao.UserInfoDao.ListById(ctx, userIdList)
	if err != nil {
		return nil, err
	}
	userItemMap := map[string]*user_dao.UserInfoDbItem{}
	for _, userItem := range userItemList {
		userItemMap[userItem.UserId] = userItem
	}
	//生产结果
	contentList := []*org_forum_api.ThreadContentInfo{}
	for _, contentItem := range contentItemList {
		content := contentItem.ToThreadContentInfo()
		userItem, ok := userItemMap[contentItem.UserId]
		if ok {
			content.UserDisplayName = userItem.BasicInfo.DisplayName
			content.UserLogoUri = userItem.BasicInfo.LogoUri
		}
		contentList = append(contentList, content)
	}
	return &org_forum_api.ListContentResponse{
		Code:        org_forum_api.ListContentResponse_CODE_OK,
		TotalCount:  threadItem.ContentCount,
		ContentList: contentList,
	}, nil
}

func (apiImpl *OrgForumApiImpl) ListContentById(ctx context.Context, req *org_forum_api.ListContentByIdRequest) (*org_forum_api.ListContentByIdResponse, error) {
	emptyList := []*org_forum_api.ThreadContentInfo{}

	sessionItem, ok := dao.CacheDao.GetSession(ctx, req.SessionId)
	if !ok {
		return &org_forum_api.ListContentByIdResponse{
			Code:        org_forum_api.ListContentByIdResponse_CODE_WRONG_SESSION,
			ErrMsg:      "会话不存在",
			ContentList: emptyList,
		}, nil
	}
	exist, err := org_dao.OrgInfoDao.Exist(ctx, req.OrgId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.ListContentByIdResponse{
			Code:        org_forum_api.ListContentByIdResponse_CODE_NO_ORG,
			ErrMsg:      "组织不存在",
			ContentList: emptyList,
		}, nil
	}
	exist, err = org_dao.MemberDao.Exist(ctx, req.OrgId, sessionItem.UserId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.ListContentByIdResponse{
			Code:        org_forum_api.ListContentByIdResponse_CODE_NO_PERMISSION,
			ErrMsg:      "没有权限",
			ContentList: emptyList,
		}, nil
	}

	contentItemList, err := org_dao.ThreadContentDao.ListById(ctx, req.OrgId, req.ContentIdList)
	if err != nil {
		return nil, err
	}
	//获取用户信息
	userIdList := []string{}
	for _, contentItem := range contentItemList {
		userIdList = append(userIdList, contentItem.UserId)
	}
	userItemList, err := user_dao.UserInfoDao.ListById(ctx, userIdList)
	if err != nil {
		return nil, err
	}
	userItemMap := map[string]*user_dao.UserInfoDbItem{}
	for _, userItem := range userItemList {
		userItemMap[userItem.UserId] = userItem
	}
	//生产结果
	contentList := []*org_forum_api.ThreadContentInfo{}
	for _, contentItem := range contentItemList {
		content := contentItem.ToThreadContentInfo()
		userItem, ok := userItemMap[contentItem.UserId]
		if ok {
			content.UserDisplayName = userItem.BasicInfo.DisplayName
			content.UserLogoUri = userItem.BasicInfo.LogoUri
		}
		contentList = append(contentList, content)
	}
	return &org_forum_api.ListContentByIdResponse{
		Code:        org_forum_api.ListContentByIdResponse_CODE_OK,
		ContentList: contentList,
	}, nil
}

func (apiImpl *OrgForumApiImpl) GetContent(ctx context.Context, req *org_forum_api.GetContentRequest) (*org_forum_api.GetContentResponse, error) {
	emptyInfo := &org_forum_api.ThreadContentInfo{}

	sessionItem, ok := dao.CacheDao.GetSession(ctx, req.SessionId)
	if !ok {
		return &org_forum_api.GetContentResponse{
			Code:        org_forum_api.GetContentResponse_CODE_WRONG_SESSION,
			ErrMsg:      "会话不存在",
			ContentInfo: emptyInfo,
		}, nil
	}
	exist, err := org_dao.OrgInfoDao.Exist(ctx, req.OrgId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.GetContentResponse{
			Code:   org_forum_api.GetContentResponse_CODE_NO_ORG,
			ErrMsg: "组织不存在",
		}, nil
	}
	exist, err = org_dao.MemberDao.Exist(ctx, req.OrgId, sessionItem.UserId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.GetContentResponse{
			Code:   org_forum_api.GetContentResponse_CODE_NO_PERMISSION,
			ErrMsg: "没有权限",
		}, nil
	}
	exist, err = org_dao.ForumDao.Exist(ctx, req.OrgId, req.ForumId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.GetContentResponse{
			Code:   org_forum_api.GetContentResponse_CODE_NO_FORUM,
			ErrMsg: "讨论组不存在",
		}, nil
	}
	exist, err = org_dao.ForumThreadDao.Exist(ctx, req.OrgId, req.ForumId, req.ThreadId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.GetContentResponse{
			Code:   org_forum_api.GetContentResponse_CODE_NO_THREAD,
			ErrMsg: "讨论会话不存在",
		}, nil
	}
	contentItem, err := org_dao.ThreadContentDao.Get(ctx, req.OrgId, req.ForumId, req.ThreadId, req.ContentId)
	if err != nil {
		return &org_forum_api.GetContentResponse{
			Code:   org_forum_api.GetContentResponse_CODE_NO_CONTENT,
			ErrMsg: "讨论内容不存在",
		}, nil
	}

	userItemList, err := user_dao.UserInfoDao.ListById(ctx, []string{contentItem.UserId})
	if err != nil {
		return nil, err
	}

	content := contentItem.ToThreadContentInfo()
	if len(userItemList) > 0 {
		content.UserDisplayName = userItemList[0].BasicInfo.DisplayName
		content.UserLogoUri = userItemList[0].BasicInfo.LogoUri
	}

	return &org_forum_api.GetContentResponse{
		Code:        org_forum_api.GetContentResponse_CODE_OK,
		ContentInfo: content,
	}, nil
}

func (apiImpl *OrgForumApiImpl) RemoveContent(ctx context.Context, req *org_forum_api.RemoveContentRequest) (*org_forum_api.RemoveContentResponse, error) {
	sessionItem, ok := dao.CacheDao.GetSession(ctx, req.SessionId)
	if !ok {
		return &org_forum_api.RemoveContentResponse{
			Code:   org_forum_api.RemoveContentResponse_CODE_WRONG_SESSION,
			ErrMsg: "会话不存在",
		}, nil
	}
	orgItem, err := org_dao.OrgInfoDao.Get(ctx, req.OrgId)
	if err != nil {
		return &org_forum_api.RemoveContentResponse{
			Code:   org_forum_api.RemoveContentResponse_CODE_NO_ORG,
			ErrMsg: "组织不存在",
		}, nil
	}
	exist, err := org_dao.MemberDao.Exist(ctx, req.OrgId, sessionItem.UserId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.RemoveContentResponse{
			Code:   org_forum_api.RemoveContentResponse_CODE_NO_PERMISSION,
			ErrMsg: "没有权限",
		}, nil
	}
	exist, err = org_dao.ForumDao.Exist(ctx, req.OrgId, req.ForumId)
	if err != nil {
		return nil, err
	}
	if !exist {
		return &org_forum_api.RemoveContentResponse{
			Code:   org_forum_api.RemoveContentResponse_CODE_NO_FORUM,
			ErrMsg: "讨论组不存在",
		}, nil
	}
	threadItem, err := org_dao.ForumThreadDao.Get(ctx, req.OrgId, req.ForumId, req.ThreadId)
	if err != nil {
		return &org_forum_api.RemoveContentResponse{
			Code:   org_forum_api.RemoveContentResponse_CODE_NO_THREAD,
			ErrMsg: "讨论会话不存在",
		}, nil
	}
	contentItem, err := org_dao.ThreadContentDao.Get(ctx, req.OrgId, req.ForumId, req.ThreadId, req.ContentId)
	if err != nil { //记录不存在
		return &org_forum_api.RemoveContentResponse{
			Code: org_forum_api.RemoveContentResponse_CODE_OK,
		}, nil
	}
	if !(orgItem.OwnerUserId == sessionItem.UserId || contentItem.UserId == sessionItem.UserId) {
		return &org_forum_api.RemoveContentResponse{
			Code:   org_forum_api.RemoveContentResponse_CODE_NO_PERMISSION,
			ErrMsg: "没有权限",
		}, nil
	}

	if req.ContentId == threadItem.FirstContentId {
		return &org_forum_api.RemoveContentResponse{
			Code:   org_forum_api.RemoveContentResponse_CODE_NO_PERMISSION,
			ErrMsg: "没有权限",
		}, nil
	}

	dbSess, err := dao.StartSession()
	if err != nil {
		return nil, err
	}
	defer dao.EndSession(dbSess)

	ret, err := dbSess.WithTransaction(ctx, func(sessCtx mongo.SessionContext) (interface{}, error) {
		err = org_dao.ThreadContentDao.Remove(sessCtx, req.OrgId, req.ForumId, req.ThreadId, req.ContentId)
		if err != nil {
			return nil, err
		}
		//更新会话计数
		count, err := org_dao.ThreadContentDao.CountByThread(sessCtx, req.OrgId, req.ForumId, req.ThreadId)
		if err != nil {
			return nil, err
		}
		err = org_dao.ForumThreadDao.UpdateContentCount(sessCtx, req.OrgId, req.ForumId, req.ThreadId, count)
		if err != nil {
			return nil, err
		}
		return &org_forum_api.RemoveContentResponse{
			Code: org_forum_api.RemoveContentResponse_CODE_OK,
		}, nil
	})
	if err != nil {
		return nil, err
	}
	return ret.(*org_forum_api.RemoveContentResponse), nil
}

func (apiImpl *OrgForumApiImpl) ListUserContent(ctx context.Context, req *org_forum_api.ListUserContentRequest) (*org_forum_api.ListUserContentResponse, error) {
	emptyList := []*org_forum_api.UserContentInfo{}

	sessionItem, ok := dao.CacheDao.GetSession(ctx, req.SessionId)
	if !ok {
		return &org_forum_api.ListUserContentResponse{
			Code:        org_forum_api.ListUserContentResponse_CODE_WRONG_SESSION,
			ErrMsg:      "会话不存在",
			ContentList: emptyList,
		}, nil
	}
	orgItem, err := org_dao.OrgInfoDao.Get(ctx, req.OrgId)
	if err != nil {
		return &org_forum_api.ListUserContentResponse{
			Code:        org_forum_api.ListUserContentResponse_CODE_NO_ORG,
			ErrMsg:      "组织不存在",
			ContentList: emptyList,
		}, nil
	}
	curMemberItem, err := org_dao.MemberDao.Get(ctx, req.OrgId, sessionItem.UserId)
	if err != nil {
		return &org_forum_api.ListUserContentResponse{
			Code:        org_forum_api.ListUserContentResponse_CODE_NO_PERMISSION,
			ErrMsg:      "没有权限",
			ContentList: emptyList,
		}, nil
	}
	targetMemberItem, err := org_dao.MemberDao.Get(ctx, req.OrgId, req.MemberUserId)
	if err != nil {
		return &org_forum_api.ListUserContentResponse{
			Code:        org_forum_api.ListUserContentResponse_CODE_NO_PERMISSION,
			ErrMsg:      "没有权限",
			ContentList: emptyList,
		}, nil
	}
	//检查部门层级关系
	if !(orgItem.OwnerUserId == sessionItem.UserId || req.MemberUserId == sessionItem.UserId || curMemberItem.ParentDepartMentId == "") {
		include, err := utils.CheckIncludeDepartMent(ctx, req.OrgId, targetMemberItem.ParentDepartMentId, curMemberItem.ParentDepartMentId)
		if err != nil {
			return nil, err
		}
		if !include {
			return &org_forum_api.ListUserContentResponse{
				Code:        org_forum_api.ListUserContentResponse_CODE_NO_PERMISSION,
				ErrMsg:      "没有权限",
				ContentList: emptyList,
			}, nil
		}
	}

	count, err := org_dao.ThreadContentDao.CountByUser(ctx, req.OrgId, req.MemberUserId)
	if err != nil {
		return nil, err
	}
	contentItemList, err := org_dao.ThreadContentDao.ListByUser(ctx, req.OrgId, req.MemberUserId, int64(req.Offset), int64(req.Limit))
	if err != nil {
		return nil, err
	}
	forumIdList := []string{}
	threadIdList := []string{}
	for _, contentItem := range contentItemList {
		forumIdList = append(forumIdList, contentItem.ForumId)
		threadIdList = append(threadIdList, contentItem.ThreadId)
	}
	//获取论坛信息
	forumItemList, err := org_dao.ForumDao.ListById(ctx, req.OrgId, forumIdList)
	if err != nil {
		return nil, err
	}
	forumItemMap := map[string]*org_dao.OrgForumInfoDbItem{}
	for _, forumItem := range forumItemList {
		forumItemMap[forumItem.ForumId] = forumItem
	}
	//获取会话信息
	threadItemList, err := org_dao.ForumThreadDao.ListById(ctx, req.OrgId, threadIdList)
	if err != nil {
		return nil, err
	}
	threadItemMap := map[string]*org_dao.ForumThreadInfoDbItem{}
	for _, threadItem := range threadItemList {
		threadItemMap[threadItem.ThreadId] = threadItem
	}
	//获取用户信息
	userItemList, err := user_dao.UserInfoDao.ListById(ctx, []string{req.MemberUserId})
	if err != nil {
		return nil, err
	}
	//生成结果
	contentList := []*org_forum_api.UserContentInfo{}
	for _, contentItem := range contentItemList {
		content := contentItem.ToUserContentInfo()
		forumItem, ok := forumItemMap[contentItem.ForumId]
		if ok {
			content.ForumName = forumItem.ForumName
		}
		threadItem, ok := threadItemMap[contentItem.ThreadId]
		if ok {
			content.ThreadTitle = threadItem.Title
			content.ThreadContentId = threadItem.FirstContentId
		}
		if len(userItemList) > 0 {
			content.UserDisplayName = userItemList[0].BasicInfo.DisplayName
			content.UserLogoUri = userItemList[0].BasicInfo.LogoUri
		}
		contentList = append(contentList, content)
	}

	return &org_forum_api.ListUserContentResponse{
		Code:        org_forum_api.ListUserContentResponse_CODE_OK,
		TotalCount:  count,
		ContentList: contentList,
	}, nil
}
